-
Notifications
You must be signed in to change notification settings - Fork 3
Fix vm shutdown #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix vm shutdown #34
Conversation
We always use cause=INTERNAL. Compute json payload inside ModifyVMPowerState. Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks @justinc1 👍.
Just small changes for the linters' sake.
var waitSleep time.Duration = 5 | ||
var waitTime time.Duration = 0 | ||
for { | ||
// wait on VM to stop | ||
currentState, err := utils.GetVMPowerState(vmUUID, *restClient) | ||
if err != nil { | ||
return err | ||
} | ||
if currentState == "SHUTOFF" { | ||
return nil | ||
} | ||
if waitTime > maxWaitTime { | ||
break | ||
} | ||
time.Sleep(waitSleep * time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this linter error: Multiplication of durations: 'waitSleep * time.Second' (durationcheck)
. Apparently this is a common occurrence in Golang.
According to research, time.Duration
is just another way of saying int64
. So a way to fix this could be the following:
var waitSleep time.Duration = 5 | |
var waitTime time.Duration = 0 | |
for { | |
// wait on VM to stop | |
currentState, err := utils.GetVMPowerState(vmUUID, *restClient) | |
if err != nil { | |
return err | |
} | |
if currentState == "SHUTOFF" { | |
return nil | |
} | |
if waitTime > maxWaitTime { | |
break | |
} | |
time.Sleep(waitSleep * time.Second) | |
var waitSleep time.Duration = 5 * time.Second // from ns to s | |
var waitTime time.Duration = 0 | |
for { | |
// wait on VM to stop | |
currentState, err := utils.GetVMPowerState(vmUUID, *restClient) | |
if err != nil { | |
return err | |
} | |
if currentState == "SHUTOFF" { | |
return nil | |
} | |
if waitTime > maxWaitTime { | |
break | |
} | |
time.Sleep(waitSleep) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving this PR. @justinc1, you may merge when ready.
Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
e52ff6a
to
a1e7a08
Compare
Shutdown VM before DELETE. Timeout can be set with environ HC_VM_SHUTDOWN_TIMEOUT.